package com.minimalist.basic.controller.lindi;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.contracttemplatefieldoption.LindiContractTemplateFieldOptionQueryVO;
import com.minimalist.common.entity.lindi.vo.contracttemplatefieldoption.LindiContractTemplateFieldOptionVO;
import com.minimalist.common.feign.client.lindi.LindiContractTemplateFieldOptionFeignClient;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 林地指标平台_合同模板字段选项 Controller
 *
 * @author 11987
 */
@Validated
@RestController
@RequestMapping("/basic/lindi/contractTemplateFieldOption")
@Tag(name = "林地指标平台_合同模板字段选项管理")
public class LindiContractTemplateFieldOptionController{
    private static final Logger log = LoggerFactory.getLogger(LindiContractTemplateFieldOptionController.class);


    @Autowired
    private LindiContractTemplateFieldOptionFeignClient feignClient;

    /**
     * 添加合同模板字段选项
     *
     * @param contractTemplateFieldOptionVO 合同模板字段选项信息
     * @return 成功或失败
     */
    @PostMapping("/addContractTemplateFieldOption")
    @Operation(summary = "添加合同模板字段选项")
    @SaCheckPermission("lindi:contractTemplate:add")
    public R<?> addContractTemplateFieldOption(
            @RequestBody @Validated(Add.class)
            LindiContractTemplateFieldOptionVO contractTemplateFieldOptionVO){
        contractTemplateFieldOptionVO.setCreateId(StpUtil.getLoginIdAsLong());
        contractTemplateFieldOptionVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        contractTemplateFieldOptionVO.setCreateTime(now);
        contractTemplateFieldOptionVO.setUpdateTime(now);
        return feignClient.addContractTemplateFieldOption(contractTemplateFieldOptionVO);
    }

    /**
     * 删除合同模板字段选项 -> 根据合同模板字段选项ID删除
     *
     * @param contractTemplateFieldOptionId 合同模板字段选项ID
     * @return 成功或失败
     */
    @DeleteMapping("/deleteContractTemplateFieldOptionByContractTemplateFieldOptionId")
    @Operation(summary = "删除合同模板字段选项 -> 根据合同模板字段选项ID删除")
    @SaCheckPermission("lindi:contractTemplate:delete")
    public R<?> deleteContractTemplateFieldOptionByContractTemplateFieldOptionId(
            @RequestParam("contractTemplateFieldOptionId")
            @NotNull(message = "合同模板字段选项ID不能为空")
            @Parameter(name = "contractTemplateFieldOptionId", required = true, description = "合同模板字段选项ID")
            Long contractTemplateFieldOptionId){
        return feignClient.deleteContractTemplateFieldOptionByContractTemplateFieldOptionId(contractTemplateFieldOptionId);
    }

    /**
     * 修改合同模板字段选项
     *
     * @param contractTemplateFieldOptionVO 合同模板字段选项信息
     * @return 成功或失败
     */
    @PutMapping("/updateContractTemplateFieldOptionByContractTemplateFieldOptionId")
    @Operation(summary = "修改合同模板字段选项")
    @SaCheckPermission("lindi:contractTemplate:update")
    public R<?> updateContractTemplateFieldOptionByContractTemplateFieldOptionId(
            @RequestBody @Validated(Update.class)
            LindiContractTemplateFieldOptionVO contractTemplateFieldOptionVO){
        contractTemplateFieldOptionVO.setUpdateId(StpUtil.getLoginIdAsLong());
        contractTemplateFieldOptionVO.setUpdateTime(LocalDateTime.now());
        return feignClient.updateContractTemplateFieldOptionByContractTemplateFieldOptionId(contractTemplateFieldOptionVO);
    }

    /**
     * 查询合同模板字段选项列表(分页)
     *
     * @param queryVO 查询条件
     * @return 合同模板字段选项列表
     */
    @GetMapping("/getPageContractTemplateFieldOptionList")
    @Operation(summary = "查询合同模板字段选项列表(分页)")
    @SaCheckPermission("lindi:contractTemplate:get")
    public R<PageResp<LindiContractTemplateFieldOptionVO>> getPageContractTemplateFieldOptionList(
            LindiContractTemplateFieldOptionQueryVO queryVO){
        return feignClient.getPageContractTemplateFieldOptionList(queryVO);
    }

    /**
     * 根据合同模板字段选项ID查询合同模板字段选项
     *
     * @param contractTemplateFieldOptionId 合同模板字段选项ID
     * @return 合同模板字段选项
     */
    @GetMapping("/getContractTemplateFieldOptionByContractTemplateFieldOptionId/{contractTemplateFieldOptionId}")
    @Operation(summary = "根据合同模板字段选项ID查询合同模板字段选项")
    @SaCheckPermission("lindi:contractTemplate:get")
    public R<LindiContractTemplateFieldOptionVO> getContractTemplateFieldOptionByContractTemplateFieldOptionId(
            @PathVariable(value = "contractTemplateFieldOptionId")
            @NotNull(message = "合同模板字段选项ID不能为空")
            @Parameter(name = "contractTemplateFieldOptionId", description = "合同模板字段选项ID", required = true)
            Long contractTemplateFieldOptionId){
        return feignClient.getContractTemplateFieldOptionByContractTemplateFieldOptionId(contractTemplateFieldOptionId);
    }
}
